﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace VSIX_Editor
{
    public partial class FrmSettings : VSIX_Editor.FrmMain
    {
        public Dictionary<string, string> AssembliesToExclude = new Dictionary<string, string>();
        public bool Saved = false;

        public FrmSettings()
        {
            InitializeComponent();
        }

        private void btnBack_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnBrowse_Click(object sender, EventArgs e)
        {
            if (dlgBrowse.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
            {
                AddItems(dlgBrowse.FileNames);
            }
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            FrmInput newInput = new FrmInput();
            newInput.ShowDialog(this);

            if (!newInput.Value.Equals(string.Empty))
            {
                AddItem(newInput.Value);
            }

            newInput.Close();
        }

        private void btnRemove_Click(object sender, EventArgs e)
        {
            if (lstExclude.SelectedIndex > -1)
            {
                AssembliesToExclude.Remove(lstExclude.Items[lstExclude.SelectedIndex].ToString());
                lstExclude.Items.RemoveAt(lstExclude.SelectedIndex);
            }
        }

        private void AddItem(string Item)
        {
            try
            {
                AssembliesToExclude.Add(Item, Item);
                lstExclude.Items.Add(Item);
            }
            catch { MessageBox.Show(this, "Assembly " + Item + " already added.", "Operation failed.", MessageBoxButtons.OK, MessageBoxIcon.Error); }
        }

        public void AddItems(string[] Items)
        {
            foreach (var Item in Items)
            {
                try
                {
                    AssembliesToExclude.Add(Item, Path.GetFileName(Item));
                    lstExclude.Items.Add(Path.GetFileName(Item));
                }
                catch { MessageBox.Show(this, "Assembly " + Path.GetFileName(Item) + " already added.", "Operation failed.", MessageBoxButtons.OK, MessageBoxIcon.Error); }
            }
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            Saved = true;
            this.Close();
        }

        private void FrmSettings_Load(object sender, EventArgs e)
        {
        }
    }
}
